package com.summer.data.dialect.mysql;

import com.summer.data.dialect.Dialect;
import com.summer.data.rs.extractor.KeysExtractor;
import com.summer.data.table.column.IntegerColumn;
import com.summer.data.type.NocaseMetaData;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author 345480567@qq.com
 */
public class MysqlKeysExtractor extends KeysExtractor {

    protected IntegerColumn column;

    public MysqlKeysExtractor(IntegerColumn column) {
        this.column = column;
    }

    @Override
    public void fetchKeys(ResultSet rs, Dialect dialect) throws SQLException {
        NocaseMetaData nocaseMetaData = new NocaseMetaData(rs.getMetaData(), dialect);

        Integer colPos = nocaseMetaData.findColumn("GENERATED_KEY");
        column.fetchNotNullValue(rs, colPos);
    }

}
